<?php
include_once("dbconnect/db.php");
include_once("class/Common.php");
include_once("batch/videoTool.php");
Class Format_end
{
	var $errorMessage;
	
	var $videoId;
		
	var $imgSrc = "";
	
	var $videoName = "";
	
	var $memberId = "";
	
	// 変換種類
	var $type;
	
	// メニューリンク
	var $menu_link = "";
	
	var $result_html = "";
	
	// オブジェクト生成する判断フラグ
	// 1:生成する 0:生成しない
	var $doseMakeObject = 0;
	
	var $carrierId = "";
	
	var $uId = "";

	var $cid = "";
	
	var $date;
	
	// ユーザータイプ( 0:一般,1:DL10コース,2:DL30コース,3:DL50コース)
	var $user_type;
	
	function mytask()
	{
		$common = new Common;
		$common->initCarrierInfo();	
		$this->carrierId = $common->carrierId;
		$this->uId = $common->uId;		
		$this->videoId = $_GET["videoId"];			
		$this->type = $_GET["type"];
		$this->getVideoImage();
		$this->getMenuLink();	
		$this->getResultHtml();		
	}
	
	function initForm()
	{

	}
	
	function getMenuLink()
	{
		$this->menu_link = "<hr color=\"#3399FF\" />";
		$this->menu_link .= "<a href=\"format_start.php?UID=NULLGWDOCOMO&type=1&videoId=".$this->videoId;
		$this->menu_link .= "\">動画を再生/保存する</a><br />";
		$this->menu_link .= "動画を再生したい方はこちら";
		$this->menu_link .= "<hr color=\"#3399FF\" />";
		$this->menu_link .= "<a href=\"format_start.php?UID=NULLGWDOCOMO&type=2&videoId=".$this->videoId;
		$this->menu_link .= "\">ｻﾑﾈｲﾙ画像を作る</a><br />";
		$this->menu_link .= "動画のﾜﾝｼｰﾝを選択してｻﾑﾈｲﾙ画像に変換できます。";				
		$this->menu_link .= "<hr color=\"#3399FF\" />";
		$this->menu_link .= "<a href=\"format_start.php?UID=NULLGWDOCOMO&type=3&videoId=".$this->videoId;
		$this->menu_link .= "\">ﾃﾞｺﾒ素材を作る</a> <br />";
		$this->menu_link .= "ﾃﾞｺﾒ素材として使える動くGIF画像に変換できます。";
		$this->menu_link .= "<hr color=\"#3399FF\" />";
		$this->menu_link .= "<a href=\"format_start.php?UID=NULLGWDOCOMO&type=4&videoId=".$this->videoId;
		$this->menu_link .= "\">待ち受け画像を作る</a><br />";
		$this->menu_link .= "動画のｼｰﾝで作られた壁紙画像に変換できます。";
	}
	
	function getResultHtml()
	{
		// 動画再生ダウンロードの場合
		if($this->type == 1)
		{
			// キャリアを判断する
			// docomoの場合
			if($this->carrierId == "1")
			{
				$file_number = $this->getFileNum($this->videoId,$this->carrierId);
								
				$this->result_html = "★ストリーミング再生<br />";
				
				for($i=1;$i<$file_number + 1;$i++)
				{
					$path = getDocomoS3gpDirByVideoId($this->videoId,$this->carrierId);
					//$this->result_html .= "<a href=format_end.php?doseMakeObject=1&videoId=".$this->videoId;
					//$this->result_html .="&num=".$i."&streamingFlag=1&type=".$this->type.">ビデオ".$i."</a><br/>";
					$this->result_html .="<object declare id=\"".$this->videoId."_".$i."\" data=\"".$path."/".$this->videoId."_s_".str_pad($i,3,"0",STR_PAD_LEFT).".3gp\" type=\"video/3gpp\">";
					$this->result_html .="<param name=\"stream-type\" value=\"10\" valuetype=\"data\"></object>";
					$this->result_html .="<a href=\"#".$this->videoId."_".$i."\">ビデオ".$i."</a><br/>";
				}
				
				$this->result_html .= "★ダウンロード再生<br />";
				
				for($i=1;$i<$file_number + 1;$i++)
				{
					//$this->result_html .= "<a href=format_end.php?doseMakeObject=1&videoId=".$this->videoId;
					//$this->result_html .="&num=".$i."&streamingFlag=0&type=".$this->type.">ビデオ".$i."</a><br/>";
					$path = get3gpDirByVideoId($this->videoId,$this->carrierId);
					$this->result_html .= "<a href=\"".$path."/".$this->videoId."_".str_pad($i,3,"0",STR_PAD_LEFT).".3gp\">ビデオ".$i."</a><br/>";
				}
			}
			// auの場合
			else if ($this->carrierId == "2")
			{
				$file_number = $this->getFileNum($this->videoId,$this->carrierId);
				$this->result_html .= "★ダウンロード再生<br />";
				
				for($i=1;$i<$file_number + 1;$i++)
				//for($i=1;$i<2;$i++)
				{
					$path = get3gpDirByVideoId($this->videoId,$this->carrierId);
					$size = filesize($path."/".$this->videoId."_".str_pad($i,3,"0",STR_PAD_LEFT).".3g2");
			
					$this->result_html .= "<object data=\"".$path."/".$this->videoId."_".str_pad($i,3,"0",STR_PAD_LEFT).".3g2\"".
						  " type=\"video/3gpp2\" copyright=\"no\" standby=\"ビデオ".$i."\">".
						  "<param name=\"disposition\" value=\"devmpzz\" valuetype=\"data\" />".
						  //"<param name=\"size\" value=\"".$size."\" valuetype=\"data\" />".
						  "<param name=\"title\" value=\"".substr($this->videoName,0,48)."\" valuetype=\"data\" /></object>";					
					//$this->result_html .= "<a href=format_end.php?doseMakeObject=1&videoId=".$this->videoId;
					//$this->result_html .="&num=".$i."&streamingFlag=0&type=".$this->type.">ビデオ".$i."</a><br/>";
				}				
			}
			// softbankの場合
			else if ($this->carrierId == "3")
			{
				$file_number = $this->getFileNum($this->videoId,$this->carrierId);
				
				$this->result_html .= "★ダウンロード再生<br />";
				
				$path = get3gpDirByVideoId($this->videoId,$this->carrierId);
				
				for($i=1;$i<$file_number + 1;$i++)
				{
					$this->result_html .= "<a href=".$path."/".$this->videoId."_".str_pad($i,3,"0",STR_PAD_LEFT).".3gp>"."ビデオ".$i."</a><br/>";
				}					
			}
		}
		// サムネイルの場合
		else if ($this->type == 2)
		{
			$this->result_html = "★ｻﾑﾈｲﾙ<br />画像を選んでｸﾘｯｸし、携帯端末の機能で画像を保存してお使い下さい。<br />";
			$this->result_html .= "<table><tr>";
			$datas = getThumbnailArray($this->videoId,$this->carrierId);
			$i = 0;
			foreach ($datas as $data)
			{
				$i = $i + 1;
				if($i == 3)
				{
					$this->result_html .= "<td><a href=".$data."><img src=".$data." align=left width=50/></a></td></tr><tr>";
					$i = 0;
				}
				else
				{
					$this->result_html .= "<td><a href=".$data."><img src=".$data." align=left width=50/></a></td>";
				}
			}
			$this->result_html .= "</tr><table>";
		}
		// ﾃﾞｺﾒ素材を作る 
		else if($this->type == 3)
		{
			$this->result_html = "★デコメ素材(GIFアニメ)<br />携帯端末の機能で画像を保存してお使い下さい。<br /><br />";
			
			$this->result_html .= "<a href=\"".getGifImageByVideoId($this->videoId,$this->carrierId)."\"><img src=".getGifImageByVideoId($this->videoId,$this->carrierId)." align=left></a>";
		}
		// 待ち受け画像の場合
		else if ($this->type == 4)
		{
			$this->resutl_html = "★壁紙<br />携帯端末の機能で画像を保存してお使い下さい。<br /><br />";
			
			$this->result_html .= "<a href=".getEntryImageByVideoId($this->videoId,$this->carrierId).">待ち受け画像取得</a></br><a href=".getEntryImageByVideoId($this->videoId,$this->carrierId)."><img src=".getEntryImageByVideoId($this->videoId,$this->carrierId)." align=left></a>";
		}
	}
	
	function echoObject($videoId,$carrierId,$num,$streamingFlag,$videoName)
	{
		// docomoの場合
		if($carrierId == 1)
		{
			// ストリーミングの場合
			if($streamingFlag == 1)
			{
				$path = getDocomoS3gpDirByVideoId($this->videoId,$this->carrierId);
				$objectHtml .="<object declare id=\"".$this->videoId."_".$num."\" data=\"".$path."/".$this->videoId."_s_".str_pad($num,3,"0",STR_PAD_LEFT).".3gp\" type=\"video/3gpp\">";
				$objectHtml .="<param name=\"stream-type\" value=\"10\" valuetype=\"data\"></object>";
				//$this->objectHtml .="<a href=\"#".$this->videoId."_".$i."\">ビデオ".$i."</a><br/>";
				//$objectHtml = "<object declare id=\"".$videoId."\" data=\"".$path."/".$videoId."_s_".str_pad($num,3,"0",STR_PAD_LEFT).".3gp\"".
				//			  " type=\"video/3gpp\"></object>";
			}			
			// ダウンロードの場合
			else if($streamingFlag == 0)
			{
				$path = get3gpDirByVideoId($this->videoId,$this->carrierId);
				$objectHtml = "<object declare id=\"".$videoId."\" data=\"".$path."/".$videoId."_".str_pad($num,3,"0",STR_PAD_LEFT).".3gp\"".
							  " type=\"video/3gpp\"><param name=\"count\" value=\"0\" valuetype=data></object>";	
			}
			echo $objectHtml;
		}
		// auの場合
		else
		{
			$path = get3gpDirByVideoId($this->videoId,$this->carrierId);
			$size = filesize($path."/".$videoId."_".str_pad($num,3,"0",STR_PAD_LEFT).".3g2");
			
			/*$objectHtml = "<object data=".$path."/".$videoId."_".str_pad($num,3,"0",STR_PAD_LEFT).".3g2".
						  " type=video/3gpp2 copyright=no standby=".$videoName.">".
						  "<param name=disposition value=devmpzz valuetype=data />".
						  "<param name=size value=".$size." valuetype=data />".
						  "<param name=title value=".$videoName." valuetype=data /></object>";*/
					$objectHtml = "<object declare id=\"".$this->videoId."_".$num."\" data=".$path."/".$this->videoId."_".str_pad($num,3,"0",STR_PAD_LEFT).".3g2".
						  " type=video/3gpp2 copyright=no standby=".$this->videoName.">".
						  "<param name=disposition value=devmpzz valuetype=data />".
						  "<param name=size value=".$size." valuetype=data />".
						  "<param name=title value=".$this->videoName." valuetype=data /></object>";						  
			
			echo $objectHtml;
		}
	}
	
	function getSelectSql()
	{
		$sql = "select `entrylist`.`title`,`videolist`.`cid`,`videolist`.`time` ";
		$sql = $sql."from `entrylist`,`videolist` ";
		$sql = $sql."where `videolist`.`video_id` =  ";
		$sql = $sql.$this->videoId." ";
		$sql = $sql."and `videolist`.`site_id` = 1 ";
		$sql = $sql."and `videolist`.`open_flag` = 1 ";
		$sql = $sql."and `entrylist`.`open_flag` = 1 ";
		$sql = $sql."and `videolist`.`cid` is not null ";
		$sql = $sql."and `entrylist`.`entry_id` = `videolist`.`entry_id` ";
		return $sql;
	}	
	
	function getVideoImage()
	{
		$sql = $this->getSelectSql();
		
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);

		
		if($rows > 0)
		{		
			$data = mysql_fetch_array($result);
			
			$this->videoName = $data["title"];	
				
			$this->imgSrc = "<img src=http://i1.ytimg.com/vi/".$data["cid"]."/default.jpg align=left><br><br><br><br><br>";
		}
		// データがない場合
		else
		{
			
		}
	}
	
	function getFileNum($videoId,$carrierId)
	{
		$sql = "select part_num from ex_list where video_id=".$videoId." and carrier_id=".$carrierId;
		
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		
		if($rows > 0)
		{
			$data = mysql_fetch_array($result);
			 
			 return $data["part_num"];
		}
		else
		{
			return 0;
		}
	}
}
?>